import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:nexgo_printer/enums/index.dart';
import 'package:nexgo_printer/nexgo.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String message = '';

  void _setMessage(String text) {
    setState(() => message = text);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
          children: [
            Padding(
              padding: const EdgeInsets.symmetric(
                vertical: 20,
              ),
              child: ElevatedButton(
                onPressed: () async {
                  await Nexgo.init();
                },
                child: const Text('Print init'),
              ),
            ),
            Padding(
              padding: const EdgeInsets.symmetric(
                vertical: 20,
              ),
              child: ElevatedButton(
                onPressed: () async {
                  await Nexgo.printText(
                      text: 'test!!!', align: NexgoAlignEnum.right);
                },
                child: const Text('Print test'),
              ),
            ),
            Padding(
              padding: const EdgeInsets.symmetric(
                vertical: 20,
              ),
              child: ElevatedButton(
                onPressed: () async {
                  await Nexgo.feed(val: 5);
                },
                child: const Text('feed'),
              ),
            ),
            Padding(
              padding: const EdgeInsets.symmetric(
                vertical: 20,
              ),
              child: ElevatedButton(
                onPressed: () async {
                  var bytes = await rootBundle.load("assets/1.bmp");
                  var image = bytes.buffer.asUint8List();
                  await Nexgo.printImage(
                      image: image, align: NexgoAlignEnum.center);
                  // await Nexgo.feed(val: 5);
                  // await Nexgo.printImage(image: image);
                },
                child: const Text('print Image'),
              ),
            ),
            Padding(
              padding: const EdgeInsets.symmetric(
                vertical: 20,
              ),
              child: ElevatedButton(
                onPressed: () async {
                  await Nexgo.setLEDLoading();
                },
                child: const Text('led'),
              ),
            ),
            Padding(
              padding: const EdgeInsets.symmetric(
                vertical: 20,
              ),
              child: ElevatedButton(
                onPressed: () async {
                  await Nexgo.setLEDClose();
                },
                child: const Text('led close'),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
